package com.yue92.datalife.service.impl;

import com.yue92.datalife.model.RecordItem;
import com.yue92.datalife.repository.RecordItemRepository;
import com.yue92.datalife.service.AbstractDbService;
import com.yue92.datalife.service.IRecordItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

@Service
public class RecordItemServiceImpl extends AbstractDbService<RecordItem, Long> implements IRecordItemService {

    @Autowired
    private RecordItemRepository recordItemRepository;

    @Override
    public List<RecordItem> getAllByRecordIdAndRecordDate(Long recordId, LocalDate recordDate) {
        return recordItemRepository.getAllByRecordIdAndRecordDate(recordId, recordDate);
    }

    @Override
    public Integer sum(Long recordId, LocalDate recordDate) {
        return recordItemRepository.sum(recordId, recordDate);
    }

    @Override
    public Boolean existsByRecordId(Long recordId) {
        return recordItemRepository.existsByRecordId(recordId);
    }

    @Override
    public JpaRepository<RecordItem, Long> getRepository() {
        return recordItemRepository;
    }

    @Override
    protected Class<RecordItem> getModelClass() {
        return RecordItem.class;
    }
}
